package org.example.day01;

/**
 * 第一章节1.8.1:suspend和resume方法使用
 */
public class MyThread11 extends Thread{
    private long i = 0;

    public long getI() {
        return i;
    }

    public void setI(long i) {
        this.i = i;
    }

    @Override
    public void run() {
        while(true){
            i++;
        }
    }

    /**
     * resume() 恢复线程
     * suspend() 暂停线程
     */
    public static void main(String[] args){
        try {
            MyThread11 m11 = new MyThread11();
            m11.start();
            Thread.sleep(5000);
            //A段
            m11.suspend();
            System.out.println("A= " + System.currentTimeMillis() + " i= " + m11.getI());
            Thread.sleep(5000);
            System.out.println("A= " + System.currentTimeMillis() + " i= " + m11.getI());
            //B段
            m11.resume();
            Thread.sleep(5000);
            //C段
            m11.suspend();
            System.out.println("B= " + System.currentTimeMillis() + " i= " + m11.getI());
            Thread.sleep(5000);
            System.out.println("B= " + System.currentTimeMillis() + " i= " + m11.getI());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
